<?php
	####################################################
	# library import and object instance.              #
	####################################################
	include_once('./common.php');


	####################################################
	# request data($_POST AND $_GET FROM $_REQUEST)    #
	####################################################
	# REQUEST(get and post variables)

	# GET(url variables)

	# POST(form variables)

	# Validation(special case validate)

	####################################################
	# implementation                                   #
	####################################################
	$html->set_title("test");
	$html->set_script("{$JS}jquery.1.7.1.min.js");
	$html->set_style("{$CSS}basic.css");
	$html->html_header();
$data = <<<E
CREATE TABLE `fruits_test1` (
  `fuid` int(11) NOT NULL AUTO_INCREMENT COMMENT 'pk',
  `name` varchar(255) NOT NULL COMMENT '과일이름',
  `name_eng` varchar(255) NOT NULL COMMENT '과일이름(영문)',
  `enable` enum('Y','N','ALL','NO') NOT NULL DEFAULT 'Y' COMMENT '확인',
  `description` text NOT NULL COMMENT '설명',
  PRIMARY KEY (`fuid`)
) ENGINE=MyISAM AUTO_INCREMENT=1 DEFAULT CHARSET=utf8 COMMENT='과일들';
E;
?>
<?php
$table		= array();
$st			= new ScaffoldTool();

	# 테이블 배열 제작
	$data_lines = explode("\n", $data);

	# 모든 커멘트를 제거한다.
	foreach($data_lines as $key => $val) {
		$val = trim($val);
		if ($val[0] == '-' && $val[1] == '-') {
			unset($data_lines[$key]);
		} elseif (stripos($val, 'insert into')) {
			unset($data_lines[$key]);
		}
	}

	# database type 파악
	$max = count($data_lines);
	for ($i = 1; $i < $max; $i++ ) {
		if ( strpos( trim($data_lines[$i]), "`") === 0) {
			$col = $st->find_text(trim($data_lines[$i]));
			$blob = ( stripos($data_lines[$i], 'TEXT') || stripos($data_lines[$i], 'BLOB') ) ? 1 : 0;
			$enum = ( stripos($data_lines[$i], 'enum') ) ? 1 : 0;
			$datetime = ( stripos($data_lines[$i], 'DATETIME') ) ? 1 : 0;

			$table[$col] = array('blob' => $blob, 'enum' => $enum, 'datetime' => $datetime );
			if($enum){
				$tmpval = substr($data_lines[$i], (strpos($data_lines[$i],"(")+1));
				$values = substr($tmpval, 0, (strpos($tmpval,")")));
				$values = str_replace("'","",$values);
				$values = explode(",",$values);
				$table[$col]['enum_data'] = $values;
			}
		}
	}


	Nlog::xmp($table);

?>

<?php
	$html->html_footer();
?>